package _nio._channel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Author: huangya
 * @Date: 2021/06/23
 * @Description:
 */
public class FileChannelReadDemo {

    public static void main(String[] args) throws IOException {
        File file = new File("E:\\test.txt");
        FileInputStream fis = new FileInputStream(file);
        FileChannel fileChannel = fis.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocate((int) file.length());
        fileChannel.read(byteBuffer);
        System.out.println(new String(byteBuffer.array()));

        fis.close();
    }
}
